using System;
using System.Collections;
using Steamworks;
using UnityEngine;
using _00_Source.__naptime;

public class CursorController : Singleton<CursorController>
{
	[SerializeReference]
	private Texture2D cursor;

	[SerializeField]
	private float hideTime = 4f;

	private float normalizedTime;

	private Vector2 lastPosition = Vector2.zero;

	private void Start()
	{
		Cursor.lockState = CursorLockMode.Confined;
		if (SteamUtils.IsSteamRunningOnSteamDeck())
		{
			Cursor.visible = false;
		}
	}

	public void GetNewMousePosition(Vector2 postion)
	{
		if (postion != lastPosition)
		{
			lastPosition = postion;
			normalizedTime = 0f;
			Cursor.visible = true;
		}
	}

	private void Update()
	{
		try
		{
			if (SteamUtils.IsSteamRunningOnSteamDeck())
			{
				return;
			}
		}
		catch (Exception)
		{
		}
		if (DynamicIconObserver.ConsoleBinding != 0)
		{
			Cursor.visible = false;
			return;
		}
		GetNewMousePosition(Input.mousePosition);
		if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
		{
			GetMouseClick();
		}
		if (normalizedTime < 1f)
		{
			normalizedTime += Time.unscaledDeltaTime / hideTime;
		}
		else if (Cursor.visible)
		{
			Cursor.visible = false;
		}
	}

	public void GetMouseClick()
	{
		normalizedTime = 0f;
		Cursor.visible = true;
	}

	private IEnumerator MouseCheckerCorutine()
	{
		while (true)
		{
			if (normalizedTime <= 1f)
			{
				normalizedTime += Time.deltaTime / hideTime;
				yield return null;
				continue;
			}
			if (normalizedTime != 5f)
			{
				Cursor.visible = false;
				normalizedTime = 5f;
			}
			yield return null;
		}
	}
}
